﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Services;
using Facebook;
using Facebook.Contracts;
namespace WebApplication1
{
    public partial class Publish : System.Web.UI.Page
    {
        IFacebookService facebookservice;

        protected void Page_Load(object sender, EventArgs e)
        {
            facebookservice = this.Session["facebookservice"] as IFacebookService;

            btnPublishPost.Click += new EventHandler(btnPublishPost_Click);
        }

        void btnPublishPost_Click(object sender, EventArgs e)
        {
            string textToPublish = txbPosttoPublish.Text;

            Dictionary<String, string> args = new Dictionary<string, string>();
            
            args.Add("message", textToPublish);
            if (facebookservice != null)
            {
                PublishType publishType;
                bool isEnumType = Enum.TryParse<PublishType>(this.ddlpublishType.SelectedItem.Text, false, out publishType);

                if (!isEnumType)
                {
                    publishType = PublishType.feed;
                }

                dynamic result = new object();
                //List<Dictionary<string, object>> listOfResults = (result as FBObject).Dictionary["data"] as System.Collections.ArrayList;
                if (publishType == PublishType.comments)
                {
                 
                 result=   facebookservice.Publish(this.txbGraphId.Text, publishType, args);
                  
                }

                if (publishType == PublishType.feed)
                {
                    
                 result=   facebookservice.Publish(this.txbGraphId.Text, publishType, args);
                   
                }

                if (publishType == PublishType.likes)
                {
                  result=  facebookservice.Publish(this.txbGraphId.Text, publishType, null);
                  
                }

                
                this.listOfSearchResults.DataSource = result.Properties;
                this.listOfSearchResults.DataBind();




            }

        }
    }
}